package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-maximum-number-of-non-intersecting-substrings/
 * @create 2025/10/10 12:04
 * @since JDK17
 */

public class Solution72 {
    public int maxSubstrings(String word) {
        char[] s = word.toCharArray();
        int[] h = new int[26];
        int n = s.length, ans = 0;
        Arrays.fill(h, -1);
        for (int i = 0; i < n; i++) {
            int pos = s[i] - 'a', last = h[pos];
            if (h[pos] == -1) { //
                h[pos] = i;
            }
            if (last != -1 && i - last + 1 >= 4) {  // 符合条件
                Arrays.fill(h, -1);
                ans++;
            }
        }

        return ans;
    }
}
